using System;
using System.Windows.Controls;
using System.Windows.Media;

//namespace ibba.src.sl.recursos.Codes.Extensions
//{
    public static class ValidateExtensions
    {
        private static void MarkValidate(Control pControl, bool pErro)
        {
            if (pErro)
                pControl.BorderBrush = new SolidColorBrush(Colors.Red);
            else
                pControl.BorderBrush = new SolidColorBrush(Colors.Gray);
        }

        public static bool IsNull(this TextBox pCampo, bool pMarkBrush)
        {
            //bool bNull = String.IsNullOrEmpty(((TextBox)pCampo).Text);
            bool bNull = String.IsNullOrEmpty(pCampo.Text);

            if (pMarkBrush)
                MarkValidate(pCampo, bNull);

            return bNull;
        }

        public static bool IsNull(this AutoCompleteBox pCampo, bool pMarkBrush)
        {
            bool bNull = String.IsNullOrEmpty(pCampo.Text);

            if (pMarkBrush)
                MarkValidate(pCampo, bNull);

            return bNull;
        }

        public static bool IsNull(this ComboBox pCampo, bool pMarkBrush)
        {
            bool bNull = pCampo.SelectedItem == null;

            if (pMarkBrush)
                MarkValidate(pCampo, bNull);

            return bNull;
        }

        public static bool IsNull(this DatePicker pCampo, bool pMarkBrush)
        {
            bool bNull = pCampo.SelectedDate.HasValue.Equals(false);

            if (pMarkBrush)
                MarkValidate(pCampo, bNull);

            return bNull;
        }

        public static string IfNullOrEmpty(this string pValue, string pDefaultValue)
        {
            string ret;

            if (string.IsNullOrEmpty(pValue) || pValue.Trim().Equals(""))
                ret = pDefaultValue;
            else
                ret = pValue;

            return ret;
        }

        public static string IfNull(this string pValue, string pDefaultValue)
        {
            return (pValue == null ? pDefaultValue : pValue);
        }

        public static DateTime IfNull(this DateTime pValue, DateTime pDefaultValue)
        {
            bool bNull = (pValue == null || pValue.Equals(default(DateTime)));

            return (bNull ? pDefaultValue : pValue);
        }

    }
//}